//
//  JJExtension.swift
//  Weibo
//
//  Created by Adobe on 15/9/27.
//  Copyright © 2015年 龚巨军. All rights reserved.
//

import UIKit

extension  UIBarButtonItem
{
    class func createBarButtonItem (imageName:String ,target:AnyObject?,actionName:String) ->UIBarButtonItem {
        
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named:imageName +  "_highlighted"), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        btn.addTarget(target, action: Selector(actionName), forControlEvents:UIControlEvents.TouchUpInside )
        
        return UIBarButtonItem(customView: btn)
    }
    
    
    convenience init(imageName:String ,target:AnyObject?,actionName:String ) {
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        btn.sizeToFit()
        
        btn.addTarget(target, action: Selector(actionName), forControlEvents: UIControlEvents.TouchUpInside)
        
        self.init(customView: btn)
    }
}
